package com.hua.designpattern.j2eepattern.servicelocator;

public class ServiceLocator {
	private static ServiceCache cache = new ServiceCache();

	private JNDIConcrete jndiLookup;

	public ServiceInterface getService(String jndiName) {
		ServiceInterface result = cache.getService(jndiName);
		if (result == null) {
			jndiLookup = new JNDIConcrete();
			result = jndiLookup.lookup(jndiName);
			if (result != null) {
				cache.addCache(result);
			}
		}
		return result;
	}
}
